from src.celery.main import app
from src.ai.multimModaImageTextSearch import multimModaImageTextSearch
import celery
from src.utils import *

class MyTask(celery.Task):
    # 任务失败时执行
    def on_failure(self, exc, task_id, args, kwargs, einfo):
        print('{0!r} failed: {1!r}'.format(task_id, exc))
    # 任务成功时执行
    def on_success(self, retval, task_id, args, kwargs):
        # print("--------------------------: ",socketio.app())
        print("task_id: ", task_id)
        print("retval: ", retval)
        print("args: ", args)
        print("kwargs: ", kwargs)
        print("任务成功时执行")
        pass
    # 任务重试时执行
    def on_retry(self, exc, task_id, args, kwargs, einfo):
        pass

@app.task(base=MyTask, bind=True)
def start_ai_img(self, keyWord: str, imgList: list[str]):
    try:
        image = multimModaImageTextSearch(
            key=keyWord,
            imgList=imgList
        )
        res = image.start()
        return res
    
    except Exception as exc:
        raise self.retry(exc=exc)
  
  